<?php
class ImpSoft_View_Helper_FormatPhone {

    public function formatPhone($phone) {
    
        $phone = preg_replace('#[^0-9]#', '', $phone);
        $length = strlen($phone);
        $area = '';
        if ($length > 10) return $phone;
        if ($length > 7)
        {
            $area = substr($phone, 0, 3);
            $phone = str_replace($area, '', $phone);
            $area = '(' . $area . ') ';
        }
        
        $pre = substr($phone, 0, 3);
        $suff = substr($phone, 3, 4);
        
        return $area . $pre . '-' . $suff;
    
    }

}